package com.example.core;

import javax.crypto.Cipher;

public class VolatileClass {
	private volatile int volatileVar = 10;
	private int nonVolatileVar = 10;
	private static int staticVar = 10;
	
	public int getVolatileVar(){
		if (volatileVar == 10){
			return volatileVar = 15;
		} else {
			return volatileVar = 12;
		}
		
	}
	
	public int getNonVolatileVar(){
		if (nonVolatileVar == 10){
			return nonVolatileVar = 16;
		} else {
			return nonVolatileVar = 13;
		}
	}
	
	public static void main(String... args){
		VolatileClass instance = new VolatileClass();
		
		new Thread(new ThreadExample(instance)).start();
		new Thread(new ThreadExample(instance)).start();
		
		
	}
	/*
	private String decrypt(String ciphertext) {
        Cipher c = Cipher.getInstance("AES");
        
        byte[] keyBytes = MessageDigest.getInstance("SHA-1").digest("s4lt184ggs${key}".getBytes())[0..<16]
        c.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, 'AES'))
        new String(c.doFinal(ciphertext.decodeBase64()))
    }
	*/
	static class ThreadExample implements Runnable{
		private VolatileClass instance;
		public ThreadExample(VolatileClass aInstance){
			instance = aInstance;
		}
		
		public void run(){
			staticVar++;
			int x = instance.getVolatileVar();
			int y = instance.getNonVolatileVar();
			System.out.println(x + " " + y);
		}
	}
}